/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.ycl.bk.e2p.ysyb.tools.fastutil;

import cn.ac.iie.di.ban.ycl.bk.e2p.ysyb.service.FJRThreadTask;
import cn.ac.iie.di.ban.ycl.bk.e2p.ysyb.tools.JdbcUtil;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author Administrator
 */
public class EnginVedioCpl {

    private static Logger logger = Logger.getLogger(EnginVedioCpl.class.getName());

    public static void main(String[] args) {
        FileReader reader = null;
        try {
            String root = System.getProperty("user.dir");
            String absolutePath = root + "/" + "oraclecpl";
            logger.info("从" + absolutePath + "恢复开始");
            reader = new FileReader(absolutePath);
            BufferedReader br = new BufferedReader(reader);
            String str = "";
            Statement st = null;
            Connection conn = null;
            int conn_Count = 0;
            while (true) {
                logger.info("connection Oracle " + conn_Count + "time -------------");
                conn = new JdbcUtil().getConnection(conn);

                if (conn != null) {
                    logger.info("connection Oracle " + conn_Count + "time success-------------");
                    break;
                }
                conn_Count++;

            }
            if (conn == null) {
                FJRThreadTask.errorFlag = 1;
                boolean flag = false;
                logger.error(" Database connection failed");
            }
            conn.setAutoCommit(false);
            while ((str = br.readLine()) != null) {
                String sql = str.split("insert2 table engine new_sql: ")[1];
                logger.info(sql);
                st = conn.createStatement();
                boolean eFlag = JdbcUtil.insert(conn, sql, st);
                if (eFlag) {
                    logger.info("insert into table engine sucess");
                }else{
                    logger.warn("inser into table engin faile "+eFlag+",sql is "+sql);
                }
            }
        } catch (FileNotFoundException ex) {
            logger.error(ex.getMessage(), ex);
        } catch (IOException ex) {
            logger.error(ex.getMessage(), ex);
        } catch (SQLException ex) {
            logger.error(ex.getMessage(), ex);
        } finally {
            try {
                reader.close();
            } catch (IOException ex) {
                logger.error(ex.getMessage(), ex);
            }
        }

    }
}
